import { request } from '@/utils/request'
import type {
  User,
  SendCodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
// 手机+密码 登录接口
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'POST', { mobile, password })
}
// 获取验证码
// login登录 register注册 changeMobile更换手机号 forgetPassword找回密码 bindMobile绑定三方登录，区分验证码
export const sendCode = (mobile: string, type: SendCodeType) =>
  request('/code', 'GET', { mobile, type })

// 短信验证码登录
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

// 获取用户信息
export const getUserInfo = () => request<UserInfo>('patient/myUser')

// 获取患者列表
export const getPatientList = () => request<PatientList>('/patient/mylist')

// 新增患者
export const addPatient = (data: Patient) =>
  request('patient/add', 'post', data)

// 编辑提交患者
export const editPatient = (data: Patient) =>
  request('patient/update', 'put', data)

// 删除患者
export const deletePatient = (id: string) =>
  request(`patient/del/${id}`, 'delete')

// 获取患者信息
export const getPatientInfo = (id: string) =>
  request<Patient>(`patient/info/${id}`)

// 携带openId检测三方登录
export const loginByQQ = (data: { openId: string; source: string }) =>
  request<User>('login/thirdparty', 'post', data)
// 绑定手机号
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('login/binding', 'post', data)
